package com.lzy.cloud.base.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.cloud.base.dto.ShopBankDto;
import com.lzy.cloud.base.dto.ShopProtocolDto;
import com.lzy.cloud.base.entity.ShopProtocol;
import com.lzy.cloud.base.mapper.ShopProtocolMapperExt;
import com.lzy.cloud.base.service.ShopProtocolService;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商家协议关联
 *
 * @author lc
 * @version 2018/8/17
 */
@Service
public class ShopProtocolServiceImpl implements ShopProtocolService {

    @Autowired
    private ShopProtocolMapperExt shopProtocolMapperExt;


    @Override
    public Long create(ShopProtocolDto dto) {
        ShopProtocol shopProtocol = DozerUtils.map(dto, ShopProtocol.class);
        return shopProtocolMapperExt.insertSelective(shopProtocol)>0?shopProtocol.getId():0;
    }

    @Override
    public PageInfo<ShopProtocolDto> selectList(Pager pager, ShopProtocolDto map) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        List<ShopProtocolDto> dtos = shopProtocolMapperExt.selectList(map);
        return new PageInfo<>(dtos);
    }

    @Override
    public Boolean update(ShopProtocolDto map) {
        return shopProtocolMapperExt.updateByPrimaryKey(DozerUtils.map(map,ShopProtocol.class))>0?true:false;
    }

    @Override
    public Boolean deleteByShopId(Long shopId) {
        return shopProtocolMapperExt.deleteByShopId(shopId)>0?true:false;
    }
}
